package org.xx.Iterator;

/**
 * 书架迭代器实现
 */
public class BookShelfIterator implements Iterator {
    /**
     * 书架
     */
    private BookShelf bookShelf;

    /**
     * 索引
     */
    private int index = 0;

    /**
     * 构造方法
     * @param bookShelf
     */
    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
    }

    /**
     * 判断是否还有下一位
     * @return
     */
    public boolean hasNext() {
        if (index < bookShelf.getLength()) {
            return true;
        }
        return false;
    }

    /**
     * 下一位元素
     * @return
     */
    public Object next() {
        Book book = bookShelf.getBook(index);
        index++;
        return book;
    }
}
